package og.example.views.classs;

import javax.swing.*;
import java.awt.*;
import og.example.controller.ClassController;
import og.example.views.MainFrame;

public class ClassFrame extends JFrame {
        public ClassFrame(){
            setTitle("添加班级");
            setSize(300,200);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            JPanel mainPanel=new JPanel();
            JPanel jPanel=new JPanel();
            JLabel jLabel=new JLabel("班级名称：");
            JTextField jTextField=new JTextField(15);
            jPanel.add(jLabel);
            jPanel.add(jTextField);
            JPanel buttonPanel=new JPanel();
            JButton addButton=new JButton("添加");
            JButton cancelButton=new JButton("返回");
            addButton.addActionListener(e -> {
                String className=jTextField.getText();
                if(className.equals("")){
                    JOptionPane.showMessageDialog(ClassFrame.this,"班级名称不能为空！");
                }else{
                    ClassController classController=new ClassController();
                    boolean flag=classController.classAdd(className);
                    if(flag){
                        JOptionPane.showMessageDialog(ClassFrame.this,"添加成功！");
                    }
                }
            });
            cancelButton.addActionListener(e -> {
                dispose();
                new MainFrame();
            });
            buttonPanel.add(addButton);
            buttonPanel.add(cancelButton);
            buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));
            mainPanel.add(jPanel);
            mainPanel.add(buttonPanel);
            mainPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,30));
            setContentPane(mainPanel);


            setVisible(true);
        }
    }

